﻿<UserControl x:Class="IssueVision.Client.AuditIssue"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:common="clr-namespace:IssueVision.Common;assembly=IssueVision.Common"
    Loaded="UserControl_Loaded" Unloaded="UserControl_Unloaded"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">

    <Grid x:Name="LayoutRoot"
          common:DefaultButtonHelper.DefaultButton="{Binding ElementName=auditButton}">
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="4*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <data:DataGrid x:Name="dataGrid_IssueHistory" Grid.Row="0" Grid.Column="0"
                       AutoGenerateColumns="False"
                       ItemsSource="{Binding Path=IssueHistorySource.View}"
                       SelectionMode="Single" IsReadOnly="True">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <cmd:EventToCommand PassEventArgsToCommand="True"
                                        Command="{Binding Path=SelectionChangedCommand}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <data:DataGrid.Columns>
                <data:DataGridTextColumn Header="ID" Binding="{Binding IssueID, Mode=OneWay}" Width="35" />
                <data:DataGridTextColumn Header="Action" Binding="{Binding Action, Mode=OneWay}" Width="*" />
                <data:DataGridTextColumn Header="Time Stamp" Binding="{Binding DateCreated, Mode=OneWay}" Width="4*" />
                <data:DataGridTextColumn Header="Status" Binding="{Binding Status.Name, Mode=OneWay}" Width="*" />
                <data:DataGridTextColumn Header="Pri" Binding="{Binding Priority, Mode=OneWay}" Width="35" />
                <data:DataGridTextColumn Header="Assigned To" Binding="{Binding AssignedToID, Mode=OneWay, TargetNullValue=Open}" Width="70" />
            </data:DataGrid.Columns>
        </data:DataGrid>
        <controls:GridSplitter Grid.Row="1" Grid.Column="0"
                               Height="14" HorizontalAlignment="Stretch"/>
        <Grid x:Name="grid_IssueHistoryItem" Grid.Row="2" Grid.Column="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="326*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="295*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="600*" />
                <ColumnDefinition Width="94*" />
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Row="0" Grid.Column="0"
                   HorizontalAlignment="Stretch" VerticalAlignment="Center"
                   Margin="4" Text="Issue Title" />
            <TextBox x:Name="textBox_IssueTitle" Grid.Row="0" Grid.Column="1"
                 VerticalAlignment="Center" IsReadOnly="True"
                 Text="{Binding Path=IssueHistoryItem.Title, Mode=OneWay}" />
            <Border Grid.Row="0" Grid.Column="2"
                BorderBrush="Silver" BorderThickness="1"
                CornerRadius="3" Margin="5">
                <StackPanel>
                    <TextBlock HorizontalAlignment="Center" Text="Issue ID" />
                    <TextBlock HorizontalAlignment="Center"
                           Text="{Binding Path=IssueHistoryItem.IssueID, Mode=OneWay, TargetNullValue='None'}" />
                </StackPanel>
            </Border>
            <ScrollViewer Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="34*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Grid.Column="0"
                               FontWeight="Bold" Margin="4" 
                               Text="Issue Info" />
                    <TextBlock Grid.Row="1" Grid.Column="0"
                               VerticalAlignment="Center" Margin="4" 
                               Text="Type" />
                    <ComboBox x:Name="comboBox_Type" Grid.Row="1" Grid.Column="1" 
                              Margin="4" MinHeight="25"
                              IsHitTestVisible="False" IsTabStop="False"
                              ItemsSource="{Binding Path=IssueTypeEntries}"
                              DisplayMemberPath="Name"
                              SelectedValuePath="IssueTypeID"
                              SelectedValue="{Binding Path=IssueHistoryItem.IssueTypeID, Mode=OneWay}" />
                    <TextBlock Grid.Row="2" Grid.Column="0"
                               VerticalAlignment="Center" Margin="4" 
                               Text="Priority" />
                    <ComboBox x:Name="comboBox_Priority" Grid.Row="2" Grid.Column="1"
                              Margin="4" MinHeight="25"
                              IsHitTestVisible="False" IsTabStop="False"
                              ItemsSource="{Binding Path=PriorityEntries}"
                              SelectedItem="{Binding Path=IssueHistoryItem.Priority, Mode=OneWay}" />
                    <TextBlock Grid.Row="3" Grid.Column="0"
                               VerticalAlignment="Center" Margin="4" 
                               Text="Severity" />
                    <ComboBox x:Name="comboBox_Severity" Grid.Row="3" Grid.Column="1"
                              Margin="4" MinHeight="25"
                              IsHitTestVisible="False" IsTabStop="False"
                              ItemsSource="{Binding Path=SeverityEntries}"
                              SelectedItem="{Binding Path=IssueHistoryItem.Severity, Mode=OneWay}" />
                    <TextBlock Grid.Row="4" Grid.Column="0"
                               VerticalAlignment="Center" Margin="4" 
                               Text="Status" />
                    <ComboBox x:Name="comboBox_Status" Grid.Row="4" Grid.Column="1"
                              Margin="4" MinHeight="25"
                              IsHitTestVisible="False" IsTabStop="False"
                              ItemsSource="{Binding Path=StatusEntries}"
                              DisplayMemberPath="Name"
                              SelectedValuePath="StatusID"
                              SelectedValue="{Binding Path=IssueHistoryItem.StatusID, Mode=OneWay}"/>
                    <TextBlock Grid.Row="5" Grid.Column="0"
                               VerticalAlignment="Center" Margin="4" 
                               Text="Substatus" />
                    <ComboBox x:Name="comboBox_Substatus" Grid.Row="5" Grid.Column="1"
                              Margin="4" MinHeight="25"
                              IsHitTestVisible="False" IsTabStop="False"
                              ItemsSource="{Binding Path=SubstatusEntriesWithNull}"
                              DisplayMemberPath="DisplayName"
                              SelectedValuePath="SubStatusId2"
                              SelectedValue="{Binding Path=IssueHistoryItem.SubStatusID, Mode=OneWay}" />
                    <TextBlock Grid.Row="6" Grid.Column="0"
                               VerticalAlignment="Center" Margin="4" 
                               Text="Platform" />
                    <data:DataGrid x:Name="dataGrid_Platform" Grid.Row="6" Grid.Column="1" Grid.RowSpan="3"
                                   VerticalAlignment="Top" Height="60" Margin="4"
                                    IsHitTestVisible="False" IsTabStop="False"
                                    ColumnWidth="Auto" AutoGenerateColumns="False" 
                                    SelectionMode="Single"
                                    ItemsSource="{Binding Path=PlatformEntries, Mode=OneWay}">
                        <data:DataGrid.Columns>
                            <data:DataGridTemplateColumn Header="Operating System" Width="Auto" SortMemberPath="OSVersion">
                                <data:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                            <TextBlock Text="{Binding OS}" />
                                            <TextBlock Text=" " />
                                            <TextBlock Text="{Binding OSVersion}" />
                                            <TextBlock Text=" (" />
                                            <TextBlock Text="{Binding Processor}" />
                                            <TextBlock Text=")" />
                                        </StackPanel>
                                    </DataTemplate>
                                </data:DataGridTemplateColumn.CellTemplate>
                            </data:DataGridTemplateColumn>
                            <data:DataGridTemplateColumn Header="Browser" Width="Auto" SortMemberPath="BrowserVersion">
                                <data:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                            <TextBlock Text="{Binding Browser}" />
                                            <TextBlock Text=" " />
                                            <TextBlock Text="{Binding BrowserVersion}" />
                                        </StackPanel>
                                    </DataTemplate>
                                </data:DataGridTemplateColumn.CellTemplate>
                            </data:DataGridTemplateColumn>
                            <data:DataGridTextColumn Header="Language" Width="*" Binding="{Binding Language}" />
                        </data:DataGrid.Columns>
                    </data:DataGrid>
                    <TextBlock Grid.Row="1" Grid.Column="2"
                               VerticalAlignment="Center" Margin="4" 
                               Text="Opened"/>
                    <TextBox Grid.Row="1" Grid.Column="3"
                             Margin="4" IsReadOnly="True"
                             Text="{Binding Path=IssueHistoryItem.OpenedDate, Mode=OneWay, StringFormat=\{0:F\}}"/>
                    <TextBlock Grid.Row="2" Grid.Column="2"
                           VerticalAlignment="Center" Margin="4" 
                           Text="Opened By" />
                    <TextBox Grid.Row="2" Grid.Column="3"
                             Margin="4" MinHeight="25" IsReadOnly="True"
                             Text="{Binding Path=IssueHistoryItem.OpenedByID, Mode=OneWay}"/>
                    <TextBlock Grid.Row="3" Grid.Column="2"
                             VerticalAlignment="Center" Margin="4" 
                             Text="Changed" />
                    <TextBox Grid.Row="3" Grid.Column="3"
                             Margin="4" IsReadOnly="True" 
                             Text="{Binding Path=IssueHistoryItem.LastChange, StringFormat=\{0:F\}}" />
                    <TextBlock Grid.Row="4" Grid.Column="2"
                             VerticalAlignment="Center" Margin="4" 
                             Text="Changed By" />
                    <TextBox Grid.Row="4" Grid.Column="3"
                             Margin="4" MinHeight="25" IsReadOnly="True"
                             Text="{Binding Path=IssueHistoryItem.ChangedByID, Mode=OneWay}"/>
                    <TextBlock Grid.Row="5" Grid.Column="2"
                             VerticalAlignment="Center" Margin="4" 
                             Text="Assigned To" />
                    <ComboBox x:Name="comboBox_AssignedTo" Grid.Row="5" Grid.Column="3"
                              Margin="4" MinHeight="25"
                              IsHitTestVisible="False" IsTabStop="False"
                              ItemsSource="{Binding Path=UserEntriesWithNull}"
                              DisplayMemberPath="DisplayName"
                              SelectedValuePath="Name"
                              SelectedValue="{Binding Path=IssueHistoryItem.AssignedToID, Mode=OneWay}" />
                    <TextBlock Grid.Row="6" Grid.Column="2"
                              VerticalAlignment="Center" Margin="4" 
                              Text="Resolution" />
                    <ComboBox x:Name="comboBox_Resolution" Grid.Row="6" Grid.Column="3"
                              Margin="4" MinHeight="25"
                              IsHitTestVisible="False" IsTabStop="False"
                              ItemsSource="{Binding Path=ResolutionEntriesWithNull}"
                              DisplayMemberPath="DisplayName"
                              SelectedValuePath="ResolutionId2"
                              SelectedValue="{Binding Path=IssueHistoryItem.ResolutionID, Mode=OneWay}" />
                    <TextBlock Grid.Row="7" Grid.Column="2"
                              VerticalAlignment="Center" Margin="4" 
                              Text="Resolved By" />
                    <TextBox Grid.Row="7" Grid.Column="3"
                              Margin="4" MinHeight="25" IsReadOnly="True"
                              Text="{Binding Path=IssueHistoryItem.ResolvedByID, Mode=OneWay}"/>
                </Grid>
            </ScrollViewer>
            <controls:GridSplitter Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3"
                               HorizontalAlignment="Stretch" />
            <controls:TabControl Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3">
                <controls:TabItem Header="Details">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="164*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Row="0" Grid.Column="0"
                               Text="Description" />
                        <TextBox x:Name="textBox_Description" Grid.Row="1" Grid.Column="0"
                             AcceptsReturn="True" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"
                             Text="{Binding Path=IssueHistoryItem.Description, Mode=OneWay}" IsReadOnly="True" />
                        <controls:GridSplitter Grid.Row="0" Grid.Column="1"  Grid.RowSpan="2"
                                           HorizontalAlignment="Stretch"/>
                        <TextBlock Grid.Row="0" Grid.Column="2"
                               Text="Repro Steps" />
                        <TextBox x:Name="textBox_ReproSteps" Grid.Row="1" Grid.Column="2"
                             AcceptsReturn="True" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" 
                             Text="{Binding Path=IssueHistoryItem.ReproSteps, Mode=OneWay}" IsReadOnly="True" />
                    </Grid>
                </controls:TabItem>
            </controls:TabControl>
        </Grid>
        <TextBlock Grid.Row="3" Grid.Column="0"
                   VerticalAlignment="Center" HorizontalAlignment="Right"
                   Margin="0,5,167,5" Text="Issue ID :" />
        <TextBox Grid.Row="3" Grid.Column="0"
                   VerticalAlignment="Center" HorizontalAlignment="Right"
                   Width="75" Height="23" Margin="0,5,86,5" 
                   Text="{Binding Path=CurrentIssueID, Mode=TwoWay}"/>
        <Button x:Name="auditButton" Grid.Row="3" Grid.Column="0"
                   VerticalAlignment="Center" HorizontalAlignment="Right"
                   Width="75" Height="23" Margin="0,5,5,5"
                   Content="Audit"
                   Command="{Binding Path=AuditIssueCommand}"/>
    </Grid>
</UserControl>
